<template>
  <div>
    <BasicDrawer
      v-bind="$attrs"
      @register="register"
      :title="displayModuleTitle"
      width="90%"
      @close="handleClose"
    >
      <a-descriptions :column="3" bordered size="middle" :labelStyle="{ width: '170px' }">
        <a-descriptions-item label="任务名称">{{ taskInfo?.tasktitle }} </a-descriptions-item>
        <a-descriptions-item label="任务分类">
          <Icon
            color="#1677ffbf"
            style="font-size: 15px"
            :icon="
              tasktypeOp?.filter((item) => item.label == taskInfo?.catname)[0]?.icon ??
              'ant-design:safety-certificate-outlined'
            "
          ></Icon>
          {{ taskInfo?.catname }}
        </a-descriptions-item>
        <a-descriptions-item label="任务状态">
          <a-tag v-if="taskInfo?.hasend === true" color="red">终止取消</a-tag>
          <a-tag
            v-else-if="taskInfo?.hasdispatch === true && taskInfo?.hasfinish === true"
            color="green"
            >已完成</a-tag
          >
          <a-tag
            v-else-if="taskInfo?.hasdispatch === true && taskInfo?.hasfinish === false"
            color="orange"
            >执行中</a-tag
          >
          <a-tag v-else-if="taskInfo?.hasdispatch === false" color="">未派单</a-tag>
        </a-descriptions-item>
        <a-descriptions-item label="计划执行时间">{{
          moment(taskInfo?.planbegintm).format('YYYY-MM-DD') +
          '~' +
          moment(taskInfo?.planendtm).format('YYYY-MM-DD')
        }}</a-descriptions-item>

        <a-descriptions-item label="计划执行周期">
          {{ taskInfo.planfrequencycount }}次
          {{
            taskInfo.planfrequencytype != 0
              ? '/' + timeOptions.find((item) => item.value == taskInfo.planfrequencytype)?.label
              : ''
          }}</a-descriptions-item
        >
        <a-descriptions-item label="实际/计划执行次数">
          {{ (taskInfo.execcount ?? '-') + '/' + (taskInfo.plantotalcount ?? '-') }}
        </a-descriptions-item>
        <a-descriptions-item label="任务内容及要求" :span="3">{{
          taskInfo?.taskcontent
        }}</a-descriptions-item>

        <a-descriptions-item label="现场签到">
          <a-tag :color="taskInfo?.needsignin ? 'red' : ''">{{
            taskInfo?.needsignin ? '是' : '否'
          }}</a-tag>
        </a-descriptions-item>

        <a-descriptions-item label="填写检查表">
          <a-tag :color="taskInfo?.needchecktable ? 'red' : ''">{{
            taskInfo?.needchecktable ? '是' : '否'
          }}</a-tag>
        </a-descriptions-item>
        <a-descriptions-item label="是否需要确认">
          <a-tag :color="taskInfo?.needconfirm ? 'red' : ''">{{
            taskInfo?.needconfirm ? '是' : '否'
          }}</a-tag>
        </a-descriptions-item>
        <a-descriptions-item label="附件">
          <a-list
            class="Alist"
            item-layout="horizontal"
            v-if="taskInfo?.taskattachment?.length > 0"
            :data-source="taskInfo?.taskattachment"
          >
            <template #renderItem="{ item }">
              <a-list-item>
                <template #actions>
                  <a @click="downloadFile(item)">下载</a>
                </template>
                <a-list-item-meta>
                  <template #title>
                    <span>{{ item.title }}</span>
                  </template>
                </a-list-item-meta>
              </a-list-item>
            </template>
          </a-list>
          <span v-else>-</span>
        </a-descriptions-item>
      </a-descriptions>
      <a-tabs v-model:activeKey="activeKey" :destroyInactiveTabPane="true" v-if="!mode">
        <a-tab-pane key="1" tab="任务分解表">
          <BasicTable
            @register="registerGroupAndItemsTable"
            size="small"
            :indentSize="30"
            :scroll="{ x: false, y: 'calc(100vh - 440px)' }"
            @fetch-success="onFetchSuccess"
          >
            <template #tasktitle="{ record }">{{ record.groupname ?? record.itemname }}</template>
            <template #status="{ record }">
              <a-tag color="red" v-if="record.hasend === true">终止/取消</a-tag>
              <a-tag color="" v-else-if="taskInfo.hasdispatch === false">未派单</a-tag>
              <a-tag color="orange" v-else-if="record.hasfinish === false">未完成</a-tag>
              <a-tag color="green" v-else-if="record.hasfinish === true">已完成</a-tag>
            </template>
            <template #transInfo="{ record }">
              <div style="display: flex; flex-wrap: nowrap; justify-content: center">
                <div class="transInfo">
                  <div>
                    <span
                      v-if="record?.transdeptid <= 0 || record?.transdeptid === record.resdeptid"
                      >{{ record.resdeptname }}</span
                    >
                    <span
                      v-else-if="
                        record?.transdeptid > 0 && record?.transdeptid !== record.resdeptid
                      "
                      >{{ record.resdeptname }}→{{ record.transdeptname }}</span
                    >
                  </div>

                  <div>
                    <span
                      v-if="
                        record?.transuserid === null ||
                        record?.transuserid === 0 ||
                        record?.transuserid === record.resuserid1 ||
                        record?.transuserid === record.resuserid2
                      "
                      >{{
                        (record.resusername1 ?? '') +
                        (record.resuserid2 !== null &&
                        record.resuserid2 !== 0 &&
                        record.resusername2
                          ? ',' + record.resusername2
                          : '')
                      }}</span
                    >
                    <span
                      v-else-if="
                        record?.transuserid !== null &&
                        record?.transuserid > 0 &&
                        record?.transuserid !== record.resuserid2 &&
                        record?.transuserid !== record.resuserid1
                      "
                      >{{
                        (record.resusername1 ?? '') +
                        (record.resuserid2 !== null &&
                        record.resuserid2 !== 0 &&
                        record.resusername2
                          ? ',' + record.resusername2
                          : '')
                      }}→{{ record.transusername ?? '' }}</span
                    >
                  </div>
                </div>
                <div class="transState">
                  <a-tag
                    v-if="
                      (record.transdeptid !== 0 || record.transuserid !== 0) &&
                      record.transhasreceive === false &&
                      !record.transreceivetm
                    "
                    >未接收</a-tag
                  >
                  <a-tag
                    color="success"
                    v-else-if="
                      (record.transdeptid !== 0 || record.transuserid !== 0) &&
                      record.transhasreceive === true &&
                      record.transreceivetm
                    "
                    >已接收</a-tag
                  >
                  <a-tag
                    color="error"
                    v-else-if="
                      (record.transdeptid !== 0 || record.transuserid !== 0) &&
                      record.transhasreceive === false &&
                      record.transreceivetm
                    "
                    >已拒收</a-tag
                  >
                </div>
              </div>
              <!-- 如当前责任部门为空或当前责任部门与责任部门相同时，显示责任部门名称； -->
              <!-- 如当前责任部门不为空切与责任部门不同时，显示为：责任部门名称→当前责任部门； -->
            </template>
            <template #action="{ column, record }">
              <TableAction
                v-if="!record.itemid"
                :actions="[
                  {
                    icon: 'ant-design:carry-out-outlined',
                    tooltip: '完成',
                    color: 'success',
                    ifShow:
                      record.hasend === false &&
                      record.hasfinish === false &&
                      taskInfo.hasdispatch === true,
                    popConfirm: {
                      title: '是否确认完成任务分组',
                      placement: 'left',
                      confirm: onFinishTaskGroupButtonClick.bind(null, record),
                    },
                  },
                  {
                    icon: 'ant-design:close-circle-outlined',
                    ifShow:
                      record.hasend === false &&
                      record.hasfinish === false &&
                      taskInfo.hasdispatch === true,
                    color: 'error',
                    tooltip: '终止',
                    popConfirm: {
                      title: '是否确认终止任务分组',
                      placement: 'left',
                      confirm: onEndTaskGroupButtonClick.bind(null, record),
                    },
                  },
                  {
                    tooltip: '继续',
                    color: 'success',
                    icon: 'ant-design:play-circle-outlined',
                    ifShow: record.hasend === true,
                    popConfirm: {
                      title: '是否确认继续任务分组',
                      placement: 'left',
                      confirm: onContinueTaskGroupButtonClick.bind(null, record),
                    },
                  },
                ]"
              />
              <TableAction
                v-else
                :actions="[
                  {
                    icon: 'ant-design:carry-out-outlined',
                    tooltip: '完成',
                    color: 'success',
                    ifShow: record.hasend === false && record.hasfinish === false,
                    popConfirm: {
                      title: '是否确认完成任务项',
                      placement: 'left',
                      confirm: onFinishTaskItemButtonClick.bind(null, record),
                    },
                  },
                  {
                    icon: 'ant-design:close-circle-outlined',
                    color: 'error',
                    ifShow: record.hasend === false && record.hasfinish === false,
                    tooltip: '终止',
                    popConfirm: {
                      title: '是否确认终止任务项',
                      placement: 'left',
                      confirm: onEndTaskItemButtonClick.bind(null, record),
                    },
                  },
                  {
                    tooltip: '继续',
                    ifShow: record.hasend === true,
                    color: 'success',
                    icon: 'ant-design:play-circle-outlined',
                    popConfirm: {
                      title: '是否确认继续任务项',
                      placement: 'left',
                      confirm: onContinueTaskItemButtonClick.bind(null, record),
                    },
                  },
                  {
                    tooltip: '转交',
                    ifShow: record.hasend === false && record.hasfinish === false,
                    icon: 'ant-design:swap-outlined',
                    onClick: onDispatchTaskItemButtonClick.bind(null, record),
                  },
                  {
                    tooltip: '报告',
                    icon: 'ant-design:file-text-outlined',
                    color: 'success',
                    onClick: onRecordButtonClick.bind(null, record),
                  },
                ]"
              />
            </template>
          </BasicTable>
        </a-tab-pane>
        <a-tab-pane key="2" tab="执行情况一览" v-if="taskInfo.hasdispatch === true">
          <a-alert
            message="单元格显示的数字含义：实际执行次数/计划执行次数；单元格背景颜色含义：白色-计划执行时间未到、灰色-任务已终止/取消、绿色-任务已完成、黄色-任务超时完成、红色-任务未完成。"
            type="info"
            show-icon
          />
          <BasicTable
            size="small"
            @register="registerTaskExcuteSituation"
            :data-source="executeSituation"
            :columns="executeColumns"
            :scroll="{ x: false, y: 'calc(100vh - 480px)' }"
          >
          </BasicTable>
        </a-tab-pane>
        <a-tab-pane key="3" tab="任务执行记录" v-if="taskInfo.hasdispatch === true">
          <BasicTable
            size="small"
            @register="registerTaskExecutesTable"
            :indentSize="30"
            :scroll="{ x: false, y: 'calc(100vh - 440px)' }"
          >
            <template #itemname="{ record }">
              <span @click="onExecuteRecordInfoViewButtonClick(record)">
                {{ record.item?.itemname }}</span
              >
            </template>
            <template #unitname="{ record }">
              {{ record.unitname
              }}{{
                record.hazardname || record.facilityname
                  ? '(' + (record.hazardname ?? '') + (record.facilityname ?? '') + ')'
                  : ''
              }}
            </template>
            <template #status="{ record }">
              <a-tag v-if="record.hasconfirm === true" color="green">已确认</a-tag>
              <a-tag v-else-if="record.hasexec === false" color="red">未完成</a-tag>
              <a-tag v-else-if="record.hasexec === true" color="yellow">已完成</a-tag>

              <a-tag
                style="margin-left: 5px"
                v-if="record.hasexec === true && record.isnormal === true"
                color="green"
                >正常</a-tag
              >
              <a-tag
                style="margin-left: 5px"
                v-if="record.hasexec === true && record.isnormal === false"
                color="red"
                >异常</a-tag
              >
            </template>
            <template #action="{ column, record }">
              <TableAction
                v-if="record.hasexec === true && record.hasconfirm === false"
                :actions="[
                  {
                    icon: 'ant-design:check-outlined',
                    color: 'success',
                    tooltip: '确认执行记录',
                    onClick: onConfirmExecuteButtonClick.bind(null, record),
                  },
                ]"
              />
            </template>
          </BasicTable>
        </a-tab-pane>
        <a-tab-pane key="4" size="small" tab="危险源辨识记录" v-if="taskInfo.hasdispatch === true">
          <BasicTable
            @register="registerIdentifyLogTable"
            :scroll="{ x: false, y: 'calc(100vh - 440px)' }"
          >
            <template #ismajor="{ column, record }">
              <div v-if="record.ismajor !== undefined">
                <a-tag v-if="record.ismajor == true" color="#cd201f">重大</a-tag>
                <a-tag v-else-if="record.ismajor == false" color="#3b5999">一般</a-tag>
              </div>
            </template>
            <template #identificationresult="{ record }">
              <a-tag
                v-if="
                  record.identificationresult !== null && record.identificationresult !== undefined
                "
                :color="
                  identifyOptions?.filter((item) => item.value == record.identificationresult)[0]
                    ?.color
                "
              >
                {{
                  identifyOptions?.filter((item) => item.value == record.identificationresult)[0]
                    ?.text
                }}</a-tag
              >
            </template>
          </BasicTable>
        </a-tab-pane>
      </a-tabs>
    </BasicDrawer>
    <ExecuteRecordInfoView
      @register="registerExecuteRecordInfoViewModal"
      @success="taskExecutesReload"
    />
    <ConfirmExecuteDrawer @register="registerConfirmExecuteDrawer" @success="taskExecutesReload" />
    <TransmitTaskItemModal
      @register="registerTransmitTaskItemModal"
      @success="groupsAndItemsReload"
    />
  </div>
</template>

<script lang="ts">
  import {
    h,
    defineComponent,
    ref,
    unref,
    computed,
    reactive,
    onMounted,
    watch,
    customRef,
    nextTick,
  } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { queryEnumOption } from '/@/api/qms/exchangeData';
  import { Tag } from 'ant-design-vue';
  import { useModal } from '/@/components/Modal';
  import { BasicDrawer, useDrawerInner, useDrawer } from '/@/components/Drawer';
  import { QcUnifyTransToChildProps } from '/#/QcUnify';
  import { displayTitle } from '/@/utils/QcUnifyUtil';
  import { getTaskInfo } from '/@/api/ehs/task';
  import moment from 'moment';
  import { Icon } from '/@/components/Icon';
  import { useMessage } from '/@/hooks/web/useMessage';
  const { createMessage } = useMessage();
  import { reportEhsTask } from '/@/api/ehs/taskItem';
  import {
    getTaskExecutes,
    getTaskGroupAndItem,
    getTaskSchedule,
    getTaskIdentifyRecord,
  } from '/@/api/ehs/taskConsole';
  import ExecuteRecordInfoView from '../taskBench/ExecuteRecordInfoView.vue';
  import { finishItem, endItem, continueItem } from '/@/api/ehs/taskItem';
  import { finishGroup, endGroup, continueGroup } from '/@/api/ehs/taskGroup';
  import {
    taskGroupAndItemsColumns,
    taskExecutesColumns,
    identifyRecordColumns,
  } from './taskConsole.data';
  import ConfirmExecuteDrawer from './ConfirmExecuteDrawer.vue';
  import TransmitTaskItemModal from '../taskBench/TransmitTaskItemModal.vue';
  import { downloadByUrl } from '/@/utils/file/download';
  import { useGlobSetting } from '/@/hooks/setting';
  import { getFileApi } from '/@/api/platform/file';
  import { getAllTaskCategory } from '/@/api/ehs/taskCategory';
  import { OperationTypeEnum } from '/@/enums/appEnum';
  export default defineComponent({
    props: ['mode', 'orgcode'],
    emits: ['success'],
    components: {
      BasicDrawer,
      BasicTable,
      ConfirmExecuteDrawer,
      TableAction,
      Icon,
      TransmitTaskItemModal,
      ExecuteRecordInfoView,
    },
    setup(props, { emit }) {
      const { uploadUrl } = useGlobSetting();
      const { globalProjectCode } = useGlobSetting();
      const objOptions = ref([]);
      const timeOptions = ref([]);
      const tasktypeOp = ref([]);
      const activeKey = ref('');
      const dataId = ref('');
      const identifyOptions = ref();
      const taskInfo = ref({});
      const qcUnifyProps = ref<QcUnifyTransToChildProps>();
      const executeColumns = ref([]);
      const executeSituation = ref([]);
      const orgcode = ref('');
      const [registerExecuteRecordInfoViewModal, { openModal: openExecuteRecordInfoViewModal }] =
        useModal();
      const [registerConfirmExecuteDrawer, { openDrawer: openConfirmExecuteDrawer }] = useDrawer();
      const [registerTransmitTaskItemModal, { openModal: openTransmitTaskItemModal }] = useModal();
      const [register, { closeDrawer }] = useDrawerInner((data) => {
        if (data != undefined && data != null) {
          let unrefData = unref(data);
          dataId.value = data.dataId;
          qcUnifyProps.value = unrefData;
          getTask();
          if (activeKey.value == '1') {
            groupsAndItemsReload();
          } else {
            activeKey.value = '1';
          }
          console.log(props.orgcode, 'props.orgcode');
          orgcode.value = props.orgcode;
          getAllTaskCategory(props.orgcode).then((res3) => {
            tasktypeOp.value = res3?.map((option) => {
              return {
                label: option.catname,
                value: option.catcode,
                icon: option.icon,
              };
            });
          });
        }
      });
      const [registerGroupAndItemsTable, { reload: groupsAndItemsReload, expandAll }] = useTable({
        api: getTaskGroupAndItem,
        isTreeTable: true,
        columns: taskGroupAndItemsColumns,
        showTableSetting: false,
        canResize: true,
        striped: true,
        bordered: true,
        ellipsis: true,
        indexColumnProps: {
          width: 50,
        },
        pagination: false,
        beforeFetch: (params) => {
          params = dataId.value;
          return params;
        },
        afterFetch: (res) => {
          console.log('groupanditem RES', res);
          return res?.map((item) => {
            return {
              ...item.group,
              children: item.items,
            };
          });
        },
        immediate: true,
        actionColumn: {
          width: 150,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right', //表格操作列是否固定，不设置时默认固定在右侧
        },
      });

      const [registerTaskExecutesTable, { reload: taskExecutesReload }] = useTable({
        api: getTaskExecutes,
        columns: taskExecutesColumns,
        canResize: true,
        striped: true,
        bordered: true,
        ellipsis: true,
        indexColumnProps: {
          width: 50,
        },
        pagination: false,
        beforeFetch: (params) => {
          params = dataId.value;
          return params;
        },
        immediate: true,
        actionColumn: {
          width: 100,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right', //表格操作列是否固定，不设置时默认固定在右侧
        },
      });

      const [registerIdentifyLogTable, {}] = useTable({
        api: getTaskIdentifyRecord,
        columns: identifyRecordColumns,
        canResize: true,
        striped: true,
        bordered: true,
        ellipsis: true,
        indexColumnProps: {
          width: 50,
        },
        pagination: false,
        beforeFetch: (params) => {
          params = dataId.value;
          return params;
        },
        immediate: true,
      });

      const [registerTaskExcuteSituation, { setColumns }] = useTable({
        canResize: true,
        striped: true,
        bordered: true,
        ellipsis: true,
        pagination: false,
        showIndexColumn: false,
      });

      function onFetchSuccess() {
        nextTick(expandAll);
      }

      /**
       * 下载附件
       */
      function downloadFile(item) {
        downloadByUrl({ url: item.url, fileName: item.name });
      }

      /**
       * 返回JSON格式的附件信息数组
       */
      function returnAttachment(attachment) {
        return JSON.parse(attachment)?.map((item) => {
          let url = uploadUrl + getFileApi + item.id;
          let title = item.name + '.' + item.type;
          return {
            ...item,
            title,
            url,
          };
        });
      }

      function handleClose() {
        emit('success');
      }

      /**
       * 获取任务信息
       */
      function getTask() {
        getTaskInfo(dataId.value).then((res) => {
          taskInfo.value = {
            ...res,
            taskattachment: res.taskattachment ? returnAttachment(res.taskattachment) : [],
          };
        });
      }

      /**
       * 获取任务执行情况一览数据
       */
      function getExecuteSituation() {
        getTaskSchedule(dataId.value).then((res) => {
          if (res) {
            executeSituation.value = res?.groups?.map((item) => {
              let tmp = {};
              for (let i = 0; i < item.items.length; i++) {
                tmp[res.tms[i].tmstr] = item.items[i];
              }
              tmp.summary = item.summary;
              tmp.group = item.group.groupname;
              return tmp;
            });
            executeColumns.value = res?.tms?.map((item) => {
              return {
                title: item.tmstr,
                dataIndex: item.tmstr,
                align: 'center',
                width: 100,
                customRender: ({ record }) => {
                  return record[item.tmstr].execcount + '/' + item.frequencycount;
                },
                customCell: (record) => {
                  console.log(record, 'record');
                  return {
                    style: {
                      backgroundColor: moment().isBefore(
                        moment(item.begintm).format('YYYY-MM-DD HH:mm:ss'),
                      )
                        ? '#fff'
                        : record[item.tmstr].hasend === true
                        ? '#d3d3d3'
                        : record[item.tmstr].hasfinish === false
                        ? '#ff5252'
                        : record[item.tmstr].hasfinish === true &&
                          record[item.tmstr].istimeout === false
                        ? '#66e12c'
                        : record[item.tmstr].hasfinish === true &&
                          record[item.tmstr].istimeout === true
                        ? '#ebe774'
                        : '',
                    },
                  };
                },
              };
            });
            executeColumns.value.unshift({
              title: '分组/周期',
              dataIndex: 'group',
              align: 'left',
              fixed: 'left',
              width: 150,
            });
            if (res.tms.length > 1)
              executeColumns.value.push({
                title: '汇总',
                dataIndex: 'summary',
                align: 'center',
                width: 150,
                customRender: ({ record }) => {
                  return h('span', {}, record.summary.execcount);
                },
              });
            console.log(executeSituation.value, executeColumns.value, 'executeSituation');
            setColumns(executeColumns.value);
          } else {
            createMessage.error('任务执行情况获取失败');
          }
        });
      }

      /**
       * 完成任务分组
       */
      function onFinishTaskGroupButtonClick(record) {
        finishGroup(record.groupid).then((res) => {
          if (!res) {
            createMessage.success('任务分组完成成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务分组完成失败');
          }
        });
      }

      /**
       * 终止任务分组
       */
      function onEndTaskGroupButtonClick(record) {
        endGroup(record.groupid).then((res) => {
          if (!res) {
            createMessage.success('任务分组终止成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务分组终止失败');
          }
        });
      }

      /**
       * 继续任务分组
       */
      function onContinueTaskGroupButtonClick(record) {
        continueGroup(record.groupid).then((res) => {
          if (!res) {
            createMessage.success('任务分组继续成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务分组继续失败');
          }
        });
      }

      /**
       * 完成任务项
       */
      function onFinishTaskItemButtonClick(record) {
        finishItem(record.itemid).then((res) => {
          if (!res) {
            createMessage.success('任务项完成成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务项完成失败');
          }
        });
      }

      /**
       * 终止任务项
       */
      function onEndTaskItemButtonClick(record) {
        endItem(record.itemid).then((res) => {
          if (!res) {
            createMessage.success('任务项终止成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务项终止失败');
          }
        });
      }

      /**
       * 继续任务项
       */
      function onContinueTaskItemButtonClick(record) {
        continueItem(record.itemid).then((res) => {
          if (!res) {
            createMessage.success('任务项继续成功');
            groupsAndItemsReload();
          } else {
            createMessage.error('任务项继续失败');
          }
        });
      }

      /**
       * 转交任务项
       */
      function onDispatchTaskItemButtonClick(record) {
        let propsData: QcUnifyTransToChildProps = {
          moduleName: '任务项',
          operateString: '转交',
          dataId: record.itemid,
        };
        openTransmitTaskItemModal(true, propsData);
      }

      function openReport(id) {
        window.open(uploadUrl + getFileApi + id);
      }
      function onRecordButtonClick(record) {
        if (record.rptid <= 0) {
          reportEhsTask(record.itemid).then((res) => {
            if (res) {
              createMessage.success('重新生成报告成功');
              openReport(res);
            } else {
              createMessage.error('重新生成报告失败');
            }
          });
        } else {
          openReport(record.rptid);
        }
      }

      /**
       * 确认执行记录
       */
      function onConfirmExecuteButtonClick(record) {
        let propsData: QcUnifyTransToChildProps = {
          moduleName: '任务执行记录',
          operateString: '确认',
          dataId: record.execid,
        };
        openConfirmExecuteDrawer(true, propsData);
      }

      /**
       * 查看指定执行记录
       */
      function onExecuteRecordInfoViewButtonClick(record) {
        let propsData: QcUnifyTransToChildProps = {
          moduleName: '任务执行记录',
          operateType: OperationTypeEnum.VIEW,
          dataId: record.execid,
        };
        openExecuteRecordInfoViewModal(true, propsData);
      }

      let displayModuleTitle = computed(() => {
        return displayTitle(qcUnifyProps.value);
      });

      onMounted(() => {
        orgcode.value = props.orgcode;
        queryEnumOption(
          'EhsTaskDestObjectTypeEnum,TimeRangeLengthEnum,EhsTaskCategoryTypeEnum,EhsHazardIndentificationResultTypeEnum',
        ).then((res) => {
          objOptions.value = res[0].options.map((option) => {
            return {
              value: Number(option.key),
              label: option.value,
            };
          });
          timeOptions.value = res[1].options.map((option) => {
            return {
              value: Number(option.key),
              label: option.value,
            };
          });
          identifyOptions.value = res[3].options.map((option) => {
            return {
              value: option.key,
              text: option.value,
              color: option.attribute.split('"')[3],
            };
          });
        });
      });

      watch(
        () => activeKey.value,
        (newVal, oldVal) => {
          if (newVal == '2') {
            getExecuteSituation();
          }
        },
      );
      return {
        moment,
        orgcode,
        objOptions,
        timeOptions,
        tasktypeOp,
        identifyOptions,
        register,
        registerExecuteRecordInfoViewModal,
        registerGroupAndItemsTable,
        registerTransmitTaskItemModal,
        registerTaskExecutesTable,
        registerTaskExcuteSituation,
        registerIdentifyLogTable,
        activeKey,
        taskInfo,
        displayModuleTitle,
        qcUnifyProps,
        executeSituation,
        executeColumns,
        downloadFile,
        taskExecutesReload,
        groupsAndItemsReload,
        registerConfirmExecuteDrawer,
        onFinishTaskGroupButtonClick,
        onEndTaskGroupButtonClick,
        onContinueTaskGroupButtonClick,
        onFinishTaskItemButtonClick,
        onEndTaskItemButtonClick,
        onContinueTaskItemButtonClick,
        onDispatchTaskItemButtonClick,
        onConfirmExecuteButtonClick,
        onFetchSuccess,
        onExecuteRecordInfoViewButtonClick,
        handleClose,
        onRecordButtonClick,
      };
    },
  });
</script>

<style scoped>
  .flex-row {
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
  }
  .Alist {
    flex: 1;
    margin-left: 10px;
    padding: 0 10px;
    border-left: 1px solid rgb(247, 247, 247);
  }
</style>
